< previous page page_137 next page >

Page 137
    End With
    '
End Sub
The ReadProperty method uses two parameters (property name and default value) and returns a value. This return value should be placed in the local storage variable for the Public property.
Now that all the properties are built, you need to add the code that actually validates user input. For this control, you create a single Public method that checks all three key press validation rules. Select Tools | Add Procedure and enter KeyValidate as the name. Select the Function and Public option buttons before pressing the OK button. Now add the code from Listing 5.20 to the project.
Type.gifListing 5.20. Coding the KeyValidate method.
Private Function KeyValidate(intKeyValue As Integer) As Integer
    '
    ' check value against rules
    '
    Dim strNumeric As String
    Dim strDigits As String
    '
    strNumeric = "0123456789+-."
    strDigits = "0123456789"
    '
    ' convert to uppercase
    If m_UpperCase = True Then
        intKeyValue = Asc(UCase(Chr(intKeyValue)))
    End If
    '
    ' check for digits
    If m_Digits = True Then
        If InStr(strDigits, Chr(intKeyValue)) = 0 Then
            intKeyValue = 0
            RaiseEvent DigitsError(intKeyValue)
        End If
    End If
    '
    ' check for numerics
    If m_Numeric = True Then
        If InStr(strNumeric, Chr(intKeyValue)) = 0 Then
            intKeyValue = 0
            RaiseEvent NumericError(intKeyValue)
        End If
    End If
    '
    KeyValidate = intKeyValue
    '
End Function

 
< previous page page_137 next page >

If you like this book, buy it!